//package com.yunhe.device.repository.device;
//
//import com.yunhe.device.domain.base.PointDataType;
//import com.yunhe.device.domain.device.Analog;
//import org.springframework.data.domain.Page;
//import org.springframework.data.domain.Pageable;
//import org.springframework.data.domain.Sort;
//import org.springframework.data.neo4j.annotation.Query;
//import org.springframework.data.neo4j.repository.Neo4jRepository;
//import org.springframework.data.repository.query.Param;
//import org.springframework.stereotype.Repository;
//
//import java.util.List;
//
///**
// * 点表数据仓库
// * @desc 点表数据仓库定义
// * @author liuronglei
// */
//@Repository
//public interface AnalogRepository extends Neo4jRepository<Analog, Long> {
//    /**
//     * 根据代码获得点表
//     * @param code 代码
//     */
//    @Query("match (dev)-[r:HAS_ANALOG]->(a:Analog{code:{code}})-[:POINTDATATYPE_OF]->(p) return ID(a) as id,dev.code as devCode," +
//            "r.terminalCode as terminal,p.code as MEASUREMENTTYPE,a.code as code,a.title as title,a.NAME as NAME,a.pathName as pathName," +
//            "a.pointNumber as pointNumber,a.transformRatio as transformRatio,a.formula as formula,p.unit as unit, " +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit" +
//            " union " +
//            "match (dev)-[r:HAS_ANALOG]->(a:Analog{code:{code}}) where not (a)-[:POINTDATATYPE_OF]->() " +
//            "return ID(a) as id,a.title as title,dev.code as devCode,r.terminalCode as terminal,a.MEASUREMENTTYPE as MEASUREMENTTYPE,a.code as code," +
//            "a.NAME as NAME,a.pathName as pathName,a.pointNumber as pointNumber,a.transformRatio as transformRatio,a.formula as formula,null as unit, "  +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit"+
//            " union " +
//            "match (a:Analog{code:{code}})-[:POINTDATATYPE_OF]->(p) where not ()-[:HAS_ANALOG]->(a) " +
//            "return ID(a) as id,a.title as title,a.devCode as devCode,a.terminal as terminal,p.code as MEASUREMENTTYPE,a.code as code,a.NAME as NAME," +
//            "a.pathName as pathName,a.pointNumber as pointNumber,a.transformRatio as transformRatio,a.formula as formula,p.unit as unit, " +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit" +
//            " union " +
//            "match(a:Analog{code:{code}}) where not (a)-[:HAS_ANALOG|:POINTDATATYPE_OF]-() " +
//            "return ID(a) as id,a.title as title,a.devCode as devCode,a.terminal as terminal,a.MEASUREMENTTYPE as MEASUREMENTTYPE,a.code as code," +
//            "a.NAME as NAME,a.pathName as pathName,a.pointNumber as pointNumber,a.transformRatio as transformRatio,a.formula as formula,null as unit ," +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit")
//    Analog findAnalogByCode(@Param("code") Long code);
//
//    /**
//     * 根据代码删除点表
//     * @param code 代码
//     */
//    Long deleteByCode(Long code);
//
//    /**
//     * 根据点号删除点表
//     * @param pointNumber 点号
//     */
//    Long deleteByPointNumber(Long pointNumber);
//
//    /**
//     * 根据设备代码和类型ID删除点表
//     * @param devCode 设备代码
//     * @param typeCode 点号数据类型代码
//     */
//    Long deleteByDevCodeAndTypeCode(Long devCode, Long typeCode);
//
//    /**
//     * 根据点号获得点表
//     * @param pointNumber 点号
//     */
//    @Query("match (dev)-[r:HAS_ANALOG]->(a:Analog{pointNumber:{pointNumber}})-[:POINTDATATYPE_OF]->(p:PointDataType) " +
//            "return ID(a) as id,a.title as title,dev.code as devCode, r.terminalCode as terminal, p.code as MEASUREMENTTYPE, a.code as code,"+
//            "a.NAME as NAME,a.pathName as pathName, a.pointNumber as pointNumber, a.transformRatio as transformRatio,a.formula as formula,p.unit as unit," +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit")
//    Iterable<Analog> findByPointNumber(@Param("pointNumber") Long pointNumber);
//
//    /**
//     * 根据点号获得点表（分页）
//     * @param pointNumber 点号
//     * @param pageable 分页对象
//     */
//    Page<Analog> findByPointNumber(Long pointNumber, Pageable pageable);
//
//    /**
//     * 根据点号获得点表（排序）
//     * @param pointNumber 点号
//     * @param sort 排序对象
//     */
//    Iterable<Analog> findByPointNumber(Long pointNumber, Sort sort);
//
//    /**
//     * 根据设备代码和类型代码获得点表
//     * @param devCode 设备代码
//     * @param typeCode 点号数据类型代码
//     */
//    @Query("match(dev{code:{devCode}})-[r:HAS_ANALOG]->(a:Analog)" +
//            "-[:POINTDATATYPE_OF]->(p:PointDataType{code:{typeCode}}) where p.activity=true " +
//            "return ID(a) as id,a.title as title,dev.code as devCode,r.terminalCode as terminal,p.code as MEASUREMENTTYPE,a.code as code," +
//            "a.NAME as NAME,a.pathName as pathName,a.pointNumber as pointNumber,a.transformRatio as transformRatio,a.formula as formula,p.unit as unit," +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit")
//    Analog findAnalogsByDevCodeAndTypeCode(@Param("devCode") Long devCode, @Param("typeCode") Long typeCode);
//
//    /**
//     * 根据设备代码绑定点表
//     * @param code 点表代码
//     * @param devCode 设备代码
//     * @param terminal 端子代码
//     */
//    @Query("match(d{code:{devCode}}),(a:Analog{code:{code}}) create (d)-[:HAS_ANALOG{terminalCode:{terminal}}]->(a)")
//    void bindDev(@Param("code") Long code, @Param("devCode") Long devCode, @Param("terminal") String terminal);
//
//    /**
//     * 通过代码将点号数据类型绑定到点表
//     * @param code 点表代码
//     * @param pointDataTypeCode 点号数据类型代码
//     */
//    @Query("match(n:Analog),(m:PointDataType) where n.code={code} and m.code={pointDataTypeCode} create (n)-[:POINTDATATYPE_OF]->(m)")
//    void bindPointDataTypeByCode(@Param("code") Long code, @Param("pointDataTypeCode") Long pointDataTypeCode);
//
//    /**
//     * 通过代码解绑点号数据类型
//     * @param code 点表代码
//     * @param pointDataTypeCode 点号数据类型代码
//     */
//    @Query("match(a:Analog{code:{code}})-[r:POINTDATATYPE_OF]->(p:PointDataType{code:{pointDataTypeCode}}) delete r")
//    void unbindPointDataTypeByCode(@Param("code") Long code, @Param("pointDataTypeCode") Long pointDataTypeCode);
//
//    /**
//     * 获取点表绑定的点号数据类型（根据代码）
//     * @param code 点表代码
//     * @return
//     */
//    @Query("match(a:Analog) where a.code={code} match(a)-[:POINTDATATYPE_OF]->(p) return p")
//    Iterable<PointDataType> getPointDataTypeByCode(@Param("code") Long code);
//
//    /**
//     * 解绑点表绑定的所有数据类型
//     * @param code 代码
//     */
//    @Query("match(a:Analog{code:{code}})-[r:POINTDATATYPE_OF]->(p:PointDataType) delete r")
//    void unbindAllPointDataTypesByCode(@Param("code") Long code);
//
//    /**
//     * 根据代码删除点表
//     * @param code 代码
//     */
//    @Query("match (m)-[r:HAS_ANALOG]->(a:Analog{code:{code}})<-[s:POINTDATATYPE_OF]-(p) delete r,s,a")
//    void deleteAnalogByCode(@Param("code") Long code);
//
//    /**
//     * 根据代码删除已绑定的点表
//     * @param code 代码
//     */
//    @Query("match(dev)-[q:HAS_ANALOG]->(a:Analog{code:{code}})-[r:POINTDATATYPE_OF]->(p) delete q,r,a")
//    void deleteAnalogByDevCode(@Param("code") Long code);
//
////    /**
////     * 查询全部点表(根据单位代码)
////     */
////    @Query("match(f:Firm{code:{firmCode}}) match (dev)-[r:HAS_ANALOG]-(a:Analog)-[:POINTDATATYPE_OF]-(p) where (f)-[:HAS_RESOURCE]-(a)" +
////            " return ID(a) as id,dev.code as devCode," +
////            "r.terminalCode as terminal,p.code as MEASUREMENTTYPE,a.code as code,a.NAME as NAME,a.pathName as pathName," +
////            "a.pointNumber as pointNumber,a.transformRatio as transformRatio " +
////            "union " +
////            "match(f:Firm{code:{firmCode}}) match (dev)-[r:HAS_ANALOG]-(a:Analog) where not (a)-[:POINTDATATYPE_OF]-() and (f)-[:HAS_RESOURCE]-(a)" +
////            "return ID(a) as id,dev.code as devCode," +
////            "r.terminalCode as terminal,null as MEASUREMENTTYPE,a.code as code,a.NAME as NAME,a.pathName as pathName," +
////            "a.pointNumber as pointNumber,a.transformRatio as transformRatio " +
////            "union " +
////            "match(f:Firm{code:{firmCode}}) match (a:Analog)-[:POINTDATATYPE_OF]-(p) where not ()-[:HAS_ANALOG]-(a) and (f)-[:HAS_RESOURCE]-(a)" +
////            "return ID(a) as id,null as devCode," +
////            "null as terminal,p.code as MEASUREMENTTYPE,a.code as code,a.NAME as NAME,a.pathName as pathName," +
////            "a.pointNumber as pointNumber,a.transformRatio as transformRatio " +
////            "union " +
////            "match(f:Firm{code:{firmCode}})-[:HAS_RESOURCE]-(a:Analog) where not (a)-[:HAS_ANALOG|:POINTDATATYPE_OF]-() " +
////            "return ID(a) as id,null as devCode," +
////            "null as terminal,null as MEASUREMENTTYPE,a.code as code,a.NAME as NAME,a.pathName as pathName," +
////            "a.pointNumber as pointNumber,a.transformRatio as transformRatio")
////    Iterable<Analog> findAnalogs(@Param("firmCode") Long firmCode);
//
//    /**
//     * 查询全部点表
//     */
//    @Query("match (dev)-[r:HAS_ANALOG]->(a:Analog)-[:POINTDATATYPE_OF]->(p)  return ID(a) as id,a.title as title,dev.code as devCode," +
//            "r.terminalCode as terminal,p.code as MEASUREMENTTYPE,a.code as code,a.NAME as NAME,a.pathName as pathName," +
//            "a.pointNumber as pointNumber,a.transformRatio as transformRatio,a.formula as formula,p.unit as unit, " +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit" +
//            "union " +
//            "match (dev)-[r:HAS_ANALOG]->(a:Analog) where not (a)-[:POINTDATATYPE_OF]->() return ID(a) as id,dev.code as devCode," +
//            "r.terminalCode as terminal,null as MEASUREMENTTYPE,a.code as code,a.title as title,a.NAME as NAME,a.pathName as pathName," +
//            "a.pointNumber as pointNumber,a.transformRatio as transformRatio,a.formula as formula,null as unit, " +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit" +
//            "union " +
//            "match (a:Analog)-[:POINTDATATYPE_OF]->(p) where not ()-[:HAS_ANALOG]->(a) return ID(a) as id,null as devCode," +
//            "null as terminal,p.code as MEASUREMENTTYPE,a.code as code,a.NAME as NAME,a.title as title,a.pathName as pathName," +
//            "a.pointNumber as pointNumber,a.transformRatio as transformRatio,a.formula as formula,p.unit as unit, " +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit" +
//            "union " +
//            "match(a:Analog) where not (a)-[:HAS_ANALOG|:POINTDATATYPE_OF]-() return ID(a) as id,null as devCode," +
//            "null as terminal,null as MEASUREMENTTYPE,a.code as code,a.NAME as NAME,a.title as title,a.pathName as pathName," +
//            "a.pointNumber as pointNumber,a.transformRatio as transformRatio,a.formula as formula,null as unit, " +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit")
//    Iterable<Analog> findAnalogs();
//
//    /**
//     * 解绑设备绑定的点表
//     * @param code 点表代码
//     */
//    @Query("match (dev)-[r:HAS_ANALOG]->(a:Analog{code:{code}}) delete r ")
//    void unbindAnalogDevByCode(@Param("code") Long code);
//
//    /**
//     * 解绑点表绑定的点号数据类型
//     * @param code 点表代码
//     */
//    @Query("match(a:Analog{code:{code}})-[r:POINTDATATYPE_OF]->(p:PointDataType) delete r")
//    Analog unbindAnalogPointDataTypeByCode(@Param("code") Long code);
//
//    /**
//     * 根据设备代码查找设备
//     * @param devCode 设备代码
//     */
//    @Query("match(dev) where dev.code={devCode} return dev")
//    List<Object> findDevByDevCode(@Param("devCode") Long devCode);
//
//    /**
//     * 根据设备代码获取设备的全部点表
//     * @param devCode 设备代码
//     */
//    @Query("match(dev{code:{devCode}})-[r:HAS_ANALOG]->(a:Analog)-[s:POINTDATATYPE_OF]->(p:PointDataType) " +
//            "return ID(a) as id,dev.code as devCode,r.terminalCode as terminal,p.code as typeCode,a.code as code,a.NAME as NAME," +
//            "a.title as title,a.pathName as pathName,a.pointNumber as pointNumber,a.transformRatio as transformRatio,a.formula as formula,p.unit as unit," +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit,a.sn as sn")
//    Iterable<Analog> getAnalogsByDevCode(@Param("devCode") Long devCode);
//
//    /**
//     * 根据设备代码和是否用于展示获取设备的全部点表
//     * @param devCode 设备代码
//     * @param isForShow 是否用于展示
//     */
//    @Query("match(dev{code:{devCode}})-[r:HAS_ANALOG]->(a:Analog)-[s:POINTDATATYPE_OF]->(p:PointDataType) " +
//            "where a.isForShow={isForShow} return a.isForShow as isForShow,ID(a) as id,dev.code as devCode," +
//            "r.terminalCode as terminal,p.code as typeCode,a.code as code,a.NAME as NAME,a.title as title," +
//            "a.pathName as pathName,a.pointNumber as pointNumber,a.transformRatio as transformRatio," +
//            "a.formula as formula,p.unit as unit,a.sn as sn,p.frequency as frequency")
//    Iterable<Analog> getAnalogsByDevCodeAndForShow(@Param("devCode") Long devCode,
//                                                   @Param("isForShow") Boolean isForShow);
//
//
//    /**
//     * 根据设备ID查找点号
//     * @param devIdList
//     */
//    @Query("start dev=node({devIdList}) match(dev)-[:HAS_ANALOG]->(a:Analog)-[:POINTDATATYPE_OF]->(p:PointDataType) " +
//            "return ID(a) as id,a.NAME as name,a.code as code,a.title as title,dev.code as devCode,p.code as typeCode," +
//            "a.pointNumber as pointNumber,a.formula as formula,p.unit as unit," +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit")
//    Iterable<Analog> findAnalogsByDevId(@Param("devIdList") List<Long> devIdList);
//
//    /**
//     * 查找所有有公式的点号
//     */
//    Iterable<Analog> findAnalogsByFormulaNotNull();
//
//    @Query("match (f:Firm{code:{firmCode}})-[:HAS_RESOURCE]->(a:Analog) match(dev)-[:HAS_ANALOG]->(a:Analog)-[:POINTDATATYPE_OF]->(p:PointDataType)" +
//            "return ID(a) as id,a.NAME as name,a.code as code,a.title as title,dev.code as devCode,p.code as typeCode," +
//            "a.pointNumber as pointNumber,a.formula as formula,p.unit as unit," +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit")
//    Iterable<Analog> findAnalogsByFirm(@Param("firmCode") Long firmCode);
//
//    @Query("match(dev)-[:HAS_ANALOG]->(a:Analog)-[:POINTDATATYPE_OF]->(p:PointDataType) match(f:Firm{code:{firmCode}})-[:HAS_RESOURCE]->(a) " +
//            "where a.formulaType={formulaType} return ID(a) as id,a.NAME as name,a.code as code,a.title as title,dev.code as devCode," +
//            "p.code as typeCode,a.pointNumber as pointNumber,a.formula as formula,p.unit as unit," +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit")
//    Iterable<Analog> findAnalogsByFormulaType(@Param("firmCode") Long firmCode, @Param("formulaType") String formulaType);
//
//    /**
//     * 根据采集频率查询点号
//     * @param frequency 采集频率
//     */
//    @Query("match(a:Analog) where a.frequency={frequency} return a")
//    Iterable<Analog> findAnalogsByFrequency(@Param("frequency") Integer frequency);
//
//    /**
//     * 根据设备代码列表查询点表
//     * @param devCodeList 设备代码列表
//     */
//    @Query("match(a:Analog)<-[:HAS_ANALOG]-(dev) where dev.code in {devCodeList} return a")
//    Iterable<Analog> findAnalogsByDevCodeList(@Param("devCodeList") List<Long> devCodeList);
//
//    /**
//     * 根据设备ID和子设备标签以及点号类型获得点号列表
//     * @param deviceId 设备ID
//     * @param childType 子设备标签
//     * @param pdtCodeList 点号类型
//     */
//    @Query("start p=node({deviceId}) match(p)-[:CONTAINS]->(b)-[:HAS_ANALOG]->(a:Analog)-[:POINTDATATYPE_OF]->(t:PointDataType) " +
//            "where {childType} in labels(b) and t.code in {pointDataTypeCodeList} return a.pointNumber")
//    Iterable<Analog> findChildAnalogsDevIdAndType(@Param("deviceId") Long deviceId,
//                                                  @Param("childType") String childType,
//                                                  @Param("pdtCodeList") List<Long> pdtCodeList);
//
//    /**
//     * 根据电池组ID查询单体电池电压、温度点号
//     * @param packId 电池组ID
//     */
//    @Query("match(p:Pack)-[]->(b:Battery)-[:HAS_ANALOG]->(a:Analog)-[]->(t:PointDataType) where ID(p)={packId} and t.code in {pointDataTypeCodeList} return a.pointNumber")
//    List<Long> findBatteryPnByPackAndDataType(@Param("packId") Long packId,
//                                              @Param("pointDataTypeCodeList") List<Long> pointDataTypeCodeList);
//
//    @Query("match(dev)-[:HAS_ANALOG]->(a:Analog)-[:POINTDATATYPE_OF]->(p:PointDataType) where dev.code in {devCodeList} and p.code in {typeCodeList} " +
//            "return ID(a) as id,a.NAME as name,a.code as code,a.title as title,dev.code as devCode,p.code as typeCode," +
//            "a.pointNumber as pointNumber,a.formula as formula,p.unit as unit,a.isForShow as isForShow, " +
//            "a.upperLimit as upperLimit, a.lowerLimit as lowerLimit")
//    Iterable<Analog> findAnalogsByDevCodeAndTypeCode(@Param("devCodeList") List<Long> devCodeList,
//                                                     @Param("typeCodeList") List<Long> typeCodeList);
//
//    @Query("match(dev)-[:HAS_OFFICE*0..1]->(o)-[:HAS_ANALOG]->(a:Analog)-[:POINTDATATYPE_OF]->(p:PointDataType) where ID(dev)={devId} and p.code={typeCode}" +
//            "return a")
//    List<Analog> findAnalogsByDevIdAndTypeCode(@Param("devId") Long devId, @Param("typeCode") Long typeCode);
//
//    @Query("match(dev)-[:HAS_OFFICE*0..1]->(o)-[:HAS_ANALOG{terminal:{terminal}}]->(a:Analog)-[:POINTDATATYPE_OF]->(p:PointDataType) where ID(dev)={devId} and p.code={typeCode}" +
//            "return a")
//    List<Analog> findAnalogsByDevIdAndTypeCodeAndTerminal(@Param("devId") Long devId, @Param("typeCode") Long typeCode, @Param("terminal") String terminal);
//
//    @Query("match(dev)-[:HAS_OFFICE*0..1]->(o)-[:HAS_ANALOG{meter:{meter}}]->(a:Analog)-[:POINTDATATYPE_OF]->(p:PointDataType) where ID(dev)={devId} and p.code={typeCode}" +
//            "return a")
//    List<Analog> findAnalogsByDevIdAndTypeCodeAndMeter(@Param("devId") Long devId, @Param("typeCode") Long typeCode, @Param("meter") String meter);
//
//    /**
//     * @Author HeTao
//     * @Description //根据设备代码和点号类型代码和端子获得点表对象
//     * @Date 16:51 2020/10/13
//     * @Param [devCode, typeCode, terminal]
//     * @return com.yunhe.device.domain.device.Analog
//     **/
//    @Query("match(dev{code:{devCode}})-[r:HAS_ANALOG{terminal:{terminal}}]->(a:Analog)" +
//            "-[:POINTDATATYPE_OF]->(p:PointDataType{code:{typeCode}}) where p.activity=true " +
//            "return ID(a) as id,a.title as title,dev.code as devCode,r.terminalCode as terminal,p.code as MEASUREMENTTYPE,a.code as code," +
//            "a.NAME as NAME,a.pathName as pathName,a.pointNumber as pointNumber,a.transformRatio as transformRatio,a.formula as formula,p.unit as unit," +
//            "a.isForShow as isForShow, a.upperLimit as upperLimit, a.lowerLimit as lowerLimit")
//    Analog findAnalogsByDevCodeAndTypeCodeAndTerminal(@Param("devCode") Long devCode,@Param("typeCode") Long typeCode,@Param("terminal") String terminal);
//
//    /**
//     * 根据厂房编号查询点号列表
//     * @param officeName 厂房编号
//     * @return List<Analog>
//     */
//    @Query("match(o:Office{officeName:{officeName}})-[r:HAS_ANALOG]->(a:Analog) return a")
//    Iterable<Analog> searchByOfficeName(@Param("officeName") String officeName);
//
//    /**
//     * 绑定厂房编号与点号代码
//     * @param officeName 厂房编号
//     * @param code 点号代码
//     */
//    @Query("match(o:Office{officeName:{officeName}}),(a:Analog{code:{code}}) create (o)-[:HAS_ANALOG]->(a)")
//    void bindOfficeByOfficeName(@Param("officeName") String officeName, @Param("code") Long code);
//
//    /**
//     * 解绑厂房编号与点号代码
//     * @param officeName 厂房编号
//     * @param code 点号代码
//     */
//    @Query("match(o:Office{officeName:{officeName}})-[r:HAS_ANALOG]->(a:Analog{code:{code}) delete r")
//    void unbindOfficeByOfficeName(@Param("officeName") String officeName, @Param("code") Long code);
//
//    @Query("match(dev)-[:HAS_OFFICE*0..1]->(o)-[:HAS_ANALOG{meter:{meter}}]->(a:Analog)-[:POINTDATATYPE_OF]->(p:PointDataType) where dev.code={devCode} and p.code={typeCode}" +
//            "return a")
//    Analog findAnalogsByDevCodeAndTypeCodeAndMeter(@Param("devCode") Long devCode, @Param("typeCode") Long typeCode, @Param("meter") String meter);
//}
